﻿using System.Collections;
using UnityEngine;

public class NaturalProp : MonoBehaviour
{
    public int index;

    private string propId;

    PlayerCharacterController player;

    public GameObject effectsPrefab;

    public int ranges;

    public GameObject text;
    // Use this for initialization
    void Start()
    {
        player = GameObject.FindWithTag("Player").GetComponent<PlayerCharacterController>();
        propId = gameObject.name;
        text.SetActive(false);
    }

    // Update is called once per frame
    void Update()
    {
        Vector3 target = player.transform.position + new Vector3(0, 1, 0);

        if ((target - transform.position).sqrMagnitude < ranges * ranges)
        {
            text.transform.position = transform.position + new Vector3(0, 0.7f, 0);
            text.SetActive(true);
            if (Input.GetKey(KeyCode.F))
            {
                GameData.AddProp(propId, 1);
                GameData.AddMissionPrograss(2, propId, 1);
                GameObject go = Instantiate(effectsPrefab);
                go.transform.position = transform.position;
                Destroy(go, 1);
                NaturalController.instance.Refresh(index);
                gameObject.SetActive(false);
            }
        }
    }
}
